package jeumpapayment;

import barcodelib.BarcodeFactory;

import com.google.zxing.oned.EAN13Writer;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;

public class GenerateBarcodeScreen extends MainScreen{
	private GenerateBarcodeScreen me;
	private final int WIDTH = JeumpaPayment.SCREEN_WIDTH; 
	private final int HEIGHT = JeumpaPayment.SCREEN_HEIGHT;
	
	private String phonenumber = "081317666905";
	
	public GenerateBarcodeScreen(){
		//invoke the MainScreen constructor
		super();
		this.me = this;
		VerticalFieldManager manager = (VerticalFieldManager)getMainManager();
		
		
//================================= Draw the background of the Registration Screen ==============================================================
		Bitmap bitmap = new Bitmap(WIDTH,HEIGHT);
		Graphics g = Graphics.create(bitmap);
		g.setColor(0x000000);
		g.fillRect(0, 0, WIDTH,HEIGHT);
		//g.setColor(0x4B3D39);
		//g.fillRoundRect(20,70,320,100,30,30); //untuk mengambar round box (20,70,320,200,30,30)
		//g.setColor(0x777474);
		//g.drawRoundRect(20,70,320,200,30,30); // untuk mengambar round box border
		manager.setBackground(BackgroundFactory.createBitmapBackground(bitmap));
		//manager.setBackground(BackgroundFactory.createLinearGradientBackground(0xffffff, 0xffffff, 0x000000, 0x000000));
		g.drawBitmap(0,0,JeumpaPayment.BANNER.getWidth(),JeumpaPayment.BANNER.getHeight(), JeumpaPayment.BANNER,0,0);
		//Bitmap banner = Bitmap.getBitmapResource("banner_gemini.png");
		//add(new BitmapField(banner));
		
//=================================================================================================================================================
		
	
//=========================================== Draw the bitmap for barcode ==========================================================================\
		
		// Encode input string into barcode bytes
		String sBarcode = phonenumber + BarcodeFactory.calculateCheksum(phonenumber);
		byte[] byteBarcode = new EAN13Writer().encode(sBarcode);
		
		// Draw barcode from the bytes
		Bitmap barcode = BarcodeFactory.print(sBarcode,byteBarcode,270,140);
		
		//g2.setColor(Color.WHITE);
		g.drawBitmap(25, 45, 270, 140, barcode, 0, 0); //(20, 155, 320, 270, 30, 30);
		g.setColor(0xEEC900);
		g.drawRoundRect(20,40,280,150,10,10);
		
		
//======================================================================================================================================================
		
//============================================== Laporan No Telp =====================================================================================
		
		
		//Phone number Field
		LabelField lapNoTelp = new LabelField("No Telp:"){
			
			protected void paint(Graphics g){
				
				g.setColor(0xEEC900); ////Color.FLORALWHITE
				super.paint(g);
			}
		};
		// tentukan letak untuk insert phone number
		lapNoTelp.setMargin(300,30,0,30);
		
		//add phone number field and input Box
		//add(lapNoTelp);
		//add(phoneNumber);
		g.setColor(0xEEC900);
		g.drawText("No. Telp: " + phonenumber, 25, 195);
		
//===================================================================================================================================		
		
//=============================================== Laporan no telp text Box ==========================================================
		
		RichTextField reportNoTelp = new RichTextField(){
			
			protected void paint(Graphics g){
			
			g.setColor(0xEEC900); //floralwhite
			super.paint(g);
		}
	 };
	 reportNoTelp.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
	 reportNoTelp.setPadding(3,3,3,3);
	 reportNoTelp.setMargin(-10,30,10,30); //363,30,0,30
	 reportNoTelp.setBorder(BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5),0xEEC900,Border.STYLE_SOLID)); // 0x777474
	 
	 //add the text area to screen
	 //add(reportNoTelp);
	 
	 
//======================================================================================================================================
	 

//======================================================= Label saldo =================================================================
		
	//Saldo Field
		LabelField lapSaldo = new LabelField("Saldo Anda:"){
			
			protected void paint(Graphics g){
				
				g.setColor(0xEEC900); ////Color.FLORALWHITE
				super.paint(g);
			}
		};
		// tentukan letak untuk insert phone number
		lapNoTelp.setMargin(363,30,0,30);
		
		//add phone number field and input Box
		//add(lapSaldo);
		//add(phoneNumber);
		g.drawText("Saldo Anda: ga jelas!", 25, 215);
	 
	 
	 
	}

}
